﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ProductMonitor.OpCommand
{
    public class Command : ICommand
    {
        //创建委托
        private Action action;

        //构造函数
        public Command(Action action)
        {
            this.action=action;
        }

        public event EventHandler? CanExecuteChanged;

        /// <summary>
        /// 是否执行事件
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public bool CanExecute(object? parameter)
        {
            return true;
        }

        /// <summary>
        /// 执行事件
        /// </summary>
        /// <param name="parameter"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void Execute(object? parameter)
        {
            action?.Invoke();
        }
    }
}
